package com.example.web01.service.position;

import com.example.web01.dto.StaffInformation.CareerInformationDto;
import com.example.web01.dto.department.DepartmentDto;
import com.example.web01.dto.form.NewStaffDto;
import com.example.web01.dto.position.PositionDto;
import com.example.web01.dto.staff_induction.staff_inductionDto;
import com.example.web01.mapper.position.PositionMapper;
import com.example.web01.po.department.Department;
import com.example.web01.po.position.Position;
import com.example.web01.util.CommonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PositionService {
    @Resource
    private PositionMapper positionMapper;

    public CommonResult findByPos(PositionDto dto){
        CommonResult result=new CommonResult();
        List<Position> positions = positionMapper.findByPos(dto);
        result.setResult(positions);
        return result;
    }

    public CommonResult addPosition(PositionDto dto) {
        CommonResult result=new CommonResult();
        int row = positionMapper.addPosition(dto);
        if(row == 0){
            result.setCode(100);
            result.setMsg("添加岗位失败");
        }
        return result;
    }

    public CommonResult changePosition(PositionDto dto){
        CommonResult result = new CommonResult();
        int row = positionMapper.changePosition(dto);
        if(row==0) {
            result.setCode(100);
            result.setMsg("更新失败");
        }
        return result;
    }

    public CommonResult deletePosition(PositionDto[] dtos) {
        CommonResult result = new CommonResult();
        int row = 0;
        for (PositionDto dto : dtos) {
            row += positionMapper.deletePosition(dto);
        }
        if (row < dtos.length) {
            result.setCode(100);
            result.setMsg("应删除" + dtos.length + "条数据\n" + "共删除" + row + "条数据");
        } else if (row == dtos.length) {
            result.setMsg("成功删除" + row + "条数据");
        } else {
            result.setCode(300);
            result.setMsg("删除了" + row + "条数据");
        }
        return result;
    }
}
